
package resource_builder;

import com.hitechbangla.fctu.base.map.BorderMap;
import com.hitechbangla.fctu.base.map.FCTUMap;
import com.hitechbangla.fctu.base.map.Loop;
import com.hitechbangla.fctu.base.map.Point;
//import java.awt.Point;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class BorderMapBuilder implements Serializable{
     
   public BorderMap borderMap;
   
   public static void main(String args[]) throws IOException
   {
       
    BorderMapBuilder borderMapBuilder = new BorderMapBuilder();
    borderMapBuilder.borderMap = new BorderMap();  
    File folder = new File("src\\resources\\CompleteMap\\");
    File[] files = folder.listFiles();
    List<FCTUMap> worldMap = new ArrayList<FCTUMap>();
    for (File file : files) 
    {
    Loop l = new Loop();
    Scanner dataFile = new Scanner(file);
    
    //read every line of file
  
    int i = 1;
    while(dataFile.hasNextLine())
    {
    //read one line of file
      String line;
      line = dataFile.nextLine();
      line.trim();
      if(line.isEmpty()){
          break;
      }
     // string tokenizer diye line ke vaag kore duita 
      String x = null;
      String y = null;
      StringTokenizer tok = new StringTokenizer(line, ",");
      try{
      x = tok.nextToken();      
      y = tok.nextToken();
      }catch(Exception e){
          //System.out.println(i);
          //System.out.println(" " + x);
          //System.out.println(line);
          line.trim();
          if(line == ""){
             //System.out.println("line is null");
         }
      }
      
      //System.out.println(x + " " + y);
      float x1 = Float.parseFloat(x);
      float y1 = Float.parseFloat(y);
      Point point = new Point(x1,y1);
      l.add(point);
      i++;
    }//end while      
    borderMapBuilder.borderMap.add(l); 
   }//end for 
   
   worldMap.add(borderMapBuilder.borderMap);
   //open a file and write map object to that file
   try
   {
    FileOutputStream saveFile = new FileOutputStream("src\\resources\\mapType.object");
    ObjectOutputStream save = new ObjectOutputStream(saveFile);
    save.writeObject(worldMap);
    save.close();
    //System.out.println("Done");
   }
   catch(Exception ex)
   {
       ex.printStackTrace();
   }    
   }
   
   }
